#include "theater.h"



/************************************************
 *
 *  start for movieTechnician
 *
 ************************************************/
int  main(){
    Employee * currentMT;
    int i=0;
       int temp;
       initTheater();
    currentMT=&mt;
    while(1)
    {
        /*step 1: to check the manager ask me to start or not, if not wait for*/
        AcquireLock(managerAskMTplaylock);
           temp=getMV(managerAskMTPlay);
        if(false==temp)
        {
            WaitCV(managerAskMTplaylock, mr.msgCondition);
        }
	        if(true==getMV(closeTheater)){
			ReleaseLock(managerAskMTplaylock);
			break;
		}
        setMV(managerAskMTPlay , false);
        ReleaseLock(managerAskMTplaylock);
        /*step 2: to check the seats is full or not*/
        /*AcquireLock(currentCustomerSeatedlock);
        if(!currentCustomerAllSeated) /*if not all the customer seated down, i need to wait here, customer seated add this number*/
        /*{
            WaitCV(currentCustomerSeatedlock, currentMT->lineCondition);
        }
        ReleaseLock(currentCustomerSeatedlock);*/
        /*step 3: play the movie*/
        Printf("The MovieTechnician has started the movie.\n");
        for (i = 0; i < 100; i++)
        {
            /*Yield();*/
        }
        Printf("The MovieTechnician has ended the movie.\n"); 
        /*step 4: movie over, notify the customer*/
        AcquireLock(lStopMovie);
        /*broadcast to notify all the customer to wake up, the movie is over*/
        BroadcastCV(lStopMovie, mt.msgCondition);
        Printf("The MovieTechnician has told all customers to leave the theater room.\n");
        ReleaseLock(lStopMovie);
        AcquireLock(currentCustomerSeatedlock);
           temp=getMV(currentCustomerSeated);
        if (temp) {
            WaitCV(currentCustomerSeatedlock, mt.lineCondition);
        }
        /*setMV( currentCustomerAllSeated , 0);*/
        ReleaseLock(currentCustomerSeatedlock);
        /*reset the seate state*/
        for(i=0;i< MAX_SEAT;i++){
            setMV(seatState[i],false); /*reset seat state*/
        }

        /*step 5: movie over, notify the manager*/
        AcquireLock(lMovieState);
        setMV(movieState,0);    
        ReleaseLock(lMovieState);
    }
    Exit(0);
}

